﻿using System;
using System.Diagnostics;

namespace OpenGameEngine.Base
{
    public class GameTime
    {
        private Stopwatch _stopwatch;
        private double _lastUpdate;
        private double _updateTime;

        public GameTime()
        {
            _stopwatch = new Stopwatch();
        }

        public void Start()
        {
            _stopwatch.Start();
            _lastUpdate = 0;
        }

        public void Stop()
        {
            _stopwatch.Stop();
        }

        public Double Update()
        {
            double now = ElapseTime;
            _updateTime = now - _lastUpdate;
            _lastUpdate = now;
            return _updateTime;
        }

        public Double ElapseTime
        {
            get { return (_stopwatch.ElapsedMilliseconds * 0.001); }
        }

        public double FrameTime { get { return _updateTime; } }
    }
}
